/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.report.saving;


import java.io.IOException;
import java.text.SimpleDateFormat;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import src.report.AbstractBaseReportBean;
import src.report.ReportFilter;
import src.util.Utils;
import src.view.system.CompanyBean;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class RptTransaksiTabunganBean extends AbstractBaseReportBean{
    private final String COMPILE_FILE_NAME = "saving/rptTransaksiTabungan";
    @Override
    protected JRDataSource getJRDataSource() {
        RptTransaksiTabunganDataSource ds = new RptTransaksiTabunganDataSource();
        return ds;
    }

    @Override
    protected String getCompileFileName() {
        return  COMPILE_FILE_NAME;
    }
    
    public String execute(ReportFilter reportFilter) {
	try {
            super.getReportParameters().put("p_periode", reportFilter.getTransDate1());
            super.getReportParameters().put("p_periode_end", reportFilter.getTransDate2());
                     
 
            StringBuilder where = new StringBuilder("");
            if ((reportFilter.getTransDate1()!=null)&&(reportFilter.getTransDate2()!=null))
                where.append(" and sh.trans_date between ").append(Utils.formatSqlDate(reportFilter.getTransDate1())).append(" and ")
                        .append(Utils.formatSqlDate(reportFilter.getTransDate2()));
            if (reportFilter.getCif()!=null)
                where.append(" and c.cif like '%").append(reportFilter.getCif()).append("'");
            
           /* if (where.length()>0){
                where.replace(0, 5, "");                
                where.insert(0, " where ");
            }*/
            super.getReportParameters().put("p_where", where.toString() );
            super.getReportParameters().put("p_company", new CompanyBean().loadCompanyInfo().toString());
            super.prepareReportViaConn();
        } catch (JRException | IOException e) {
                // make your own exception handling
        }

        return null;
    }
}